﻿using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyLib.Web.UI {
	/// <summary>
	/// 
	/// </summary>
	[DefaultProperty("Text")]
	[DefaultEvent("Click")]
	[Designer(typeof(System.Web.UI.Design.WebControls.LinkButtonDesigner))]
	[ToolboxData("<{0}:MyButton runat=\"server\" ></{0}:MyButton>")]
	public class MyButton : LinkButton {
		/// <summary>
		/// 
		/// </summary>
		[Themeable(false)]
		[Description("Button_CausesValidation")]
		[DefaultValue(false)]
		[Category("Behavior")]
		public override bool CausesValidation {
			get {
				var obj = ViewState["CausesValidation"];
				if (obj == null) {
					return false;
				} else {
					return (bool)obj;
				}
			}
			set {
				ViewState["CausesValidation"] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		[Category("Appearance")]
		[Bindable(false)]
		[Browsable(true)]
		[DefaultValue("")]
		public string GlyphIconCssClass {
			get {
				var obj = ViewState["GlyphIconCssClass"];

				if (obj == null) {
					return "";
				} else {
					return (string)obj;
				}
			}
			set {
				ViewState["GlyphIconCssClass"] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public MyButton() {
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="writer"></param>
		protected override void RenderContents(System.Web.UI.HtmlTextWriter writer) {
			if (!string.IsNullOrWhiteSpace(GlyphIconCssClass)) {
				writer.AddAttribute(HtmlTextWriterAttribute.Class, GlyphIconCssClass, true);
				writer.RenderBeginTag(HtmlTextWriterTag.I);
				writer.RenderEndTag();
				if (!string.IsNullOrWhiteSpace(Text)) {
					writer.Write("&nbsp;");
				}
			}
			writer.WriteEncodedText(Text);
		}
	} // end of MyButton.
}
